﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FDEE.Model
{
    /// <summary>
    /// 代表钢筋、预应力束在顺桥向的分布
    /// </summary>
    public class RebarTendonDistribute
    {
        public  Dictionary<int, double> Location=new Dictionary<int, double>();
        public int Diameter;

        public RebarTendonDistribute()
        {

        }
        /// <summary>
        /// 均布式分布规律（对称）
        /// </summary>
        /// <param name="dia">直径</param>
        /// <param name="dist">分布间距</param>
        /// <param name="numofdist">分布数量</param>
        public RebarTendonDistribute(int dia, double dist, int numofdist)
        {
            Diameter = dia;
            double x0 = dist * numofdist * -0.5;
            Location = new Dictionary<int, double>();

            for (int i = 0; i < numofdist + 1; i++)
            {
                Location.Add(i, Math.Round(x0 + dist * i,0,MidpointRounding.AwayFromZero));
            }
        }

        /// <summary>
        /// 列举式分布规律
        /// </summary>
        /// <param name="dia">直径</param>
        /// <param name="distList">间距列表</param>
        public RebarTendonDistribute(int dia, List<double> distList)
        {
            Diameter = dia;
            double x0 = distList.Sum() * -0.5;
            int i = 0;
            Location = new Dictionary<int, double>();
            Location.Add(i, x0);
            i++;
            foreach (var dd in distList)
            {
                Location.Add(i, Location.Last().Value + dd);
                i++;
            }
        }

        /// <summary>
        /// 列举式分布规律
        /// </summary>
        /// <param name="dia">直径</param>
        /// <param name="distList">间距列表</param>
        /// <param name="stNo">从第几个开始布</param>
        /// <param name="endNo">从倒数第几个截至分布</param>
        public RebarTendonDistribute(int dia, List<double> distList,int stNo=0,int endNo=0)
        {
            double x0 = distList.Sum() * -0.5;
            int i = 0;
            Location = new Dictionary<int, double>();
            double dist = 0;
            for(int n=0; n< distList.Count;n++)
            {
                dist += distList[i];
                if (n >= stNo&&n< distList.Count-endNo)
                {
                    Location.Add(i, x0 + dist);
                    i++;
                }
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public  Dictionary<int, double> Delete(List<int> list)
        {
            //复制
            Dictionary<int, double> dic = new Dictionary<int, double>();
            foreach(int item in Location.Keys)
            {
                dic.Add(item, Location[item]);
            }
            //删除
            foreach (int item in list)
            {
                if(dic.Keys.Contains(item))
                {
                    dic.Remove(item);
                }
            }
            return dic;
        }

        internal int Distance(int v1, int v2)
        {
            return (int)Math.Round(Math.Abs(Location[v1] - Location[v2]),0,MidpointRounding.AwayFromZero);
        }
    }
}
